﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Project.Database.Repository;
using Project.Database;
using Project.Models;

namespace Project.Controllers
{
    public class BudgetController : Controller
    {
        private DatabaseRepository entities = new DatabaseRepository();
        //
        // GET: /Budget/
        [Authorize(Roles = "Advertiser")]
        public ActionResult Index()
        {
            Advertiser advertiser = entities.GetAdvertiser(entities.GetUser(User.Identity.Name));
            ViewBag.Balance = advertiser.Budget.Balance;
            return View();
        }

        [Authorize(Roles = "Advertiser")]
        public ActionResult Add()
        {
            return View();
        }

        [Authorize(Roles = "Advertiser")]
        [HttpPost]
        public ActionResult Add(BalanceModel model)
        {
            Advertiser advertiser = entities.GetAdvertiser(entities.GetUser(User.Identity.Name));
            advertiser.Budget.Balance += model.Amount;
            entities.Save();
            return RedirectToAction("Index","Profile");
        }

        //
        // POST: /Budget/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Budget/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Budget/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Budget/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Budget/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
